#!/usr/bin/python
# -*- coding: iso-8859-15 -*-
import sys
import talkie
import console

console.DEBUG = False

if __name__ == '__main__':
    talkie = talkie.talkie()
    console = console.console()
    
    if len(sys.argv) > 1:
        file = open(sys.argv[1], 'r')
        i = 0
        for line in file:
            try:
                decoded = line.decode('utf8').encode('iso-8859-1')
                talkie.learn(decoded)
            except:
                console.debug("Decoding error")
                continue
            i = i + len(line.split())
        console.write("Learned " + str(i) + " words from file " + sys.argv[1])

    while not console.quit:
        sentence = console.read()
        response = talkie.communicate(sentence)
        console.write(response)
    talkie.goodbye()